# -*- coding: utf-8 -*-
from flask import Flask, request, jsonify
from flasgger import Swagger
from flask_cors import *
from config import Config
from src.similar import get_response

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
app.config['JSONIFY_MIMETYPE'] = "application/json;charset=utf-8"
CORS(app, suppors_credentials=True, resources={r'/*'})  # 设置跨域
swagger = Swagger(app)


@app.route(Config.API_INDEX + "QA", methods=['POST'])
def QAAPI():
    """
    问答匹配api
    :return:
    """
    body = request.get_json()
    text = body["text"]
    res_question, res_answer, res_thresh = get_response(text)
    return jsonify({"status": 200, "msg": "ok", "question": res_question, "answer": res_answer, "thresh": res_thresh})


if __name__ == '__main__':
    app.run('0.0.0.0', port=Config.PYTHON_PORT)
